#@layout()

#define main()
<div class="jfa-header-box" id="jfa-header-box">
	<div class="jfa-crumbs" id="jfa-crumbs">
		角色管理
	</div>
	#include("/_view/common/_header_right.html")
</div>
<div class="jfa-content-box" id="jfa-content-box">
	<div class="jfa-content" id="jfa-content">
		<div id="toolbar" class="btn-group">
	        <a class="btn btn-primary btn-sm" href="#(ctx)/admin/role/add">
				<i class="fa fa-plus"></i>
				创建角色
			</a>
	    </div>
	    
		<table id="role">
			
		</table>
	</div>
</div>
<script type="text/javascript">
var contentHeight = $("#jfa-content").height();
var datagridHeight=contentHeight;

$('#role').bootstrapTable({
    url: '#(ctx)/admin/role/list',         
    method: 'get',
    toolbar: '#toolbar',
    striped: true,
    cache: false,
    pagination: true,
    sortable: false,                    
    sortOrder: "asc",  
    queryParams: function(params){
    		var data = { 
                pageSize: params.limit,
                offset: params.offset
            };
            return data;
    },
    sidePagination: "server",
    pageNumber:1,
    toolbarAlign:"right",
    pageSize: 10,         
    pageList: [10, 20, 30, 40,50],
    search: false,
    strictSearch: true,
    showColumns: false,
    showRefresh: false,             
    minimumCountColumns: 2,
    clickToSelect: true,               
   	height: datagridHeight,
    uniqueId: "id",
    showToggle:false,
    cardView: false,
    detailView: false,
    columns: [
        {
            field: 'name',  title: '名称'
        },{
            field: 'create_at',  title: '创建时间'
        }, {
            title: '操作',formatter:operaterFormatter
        }
    ]
});


function operaterFormatter(value, row, index){
	return "<a href='#(ctx)/admin/role/edit?id="+row.id+"'>"+
	"<i class='fa fa-pencil' title='修改'></i>"+
	" </a> &nbsp"+
	"<a data-pjax href=\"#(ctx)/admin/role/assignPermissions?id="+row.id+"\">"+
	"	<i class='fa fa-user' title='分配权限'></i>"+
	"</a> &nbsp"+
	"<a  href='#' onclick='deleteRole(\""+row.id+"\")'>"+
	"	<i class='fa fa-trash' title='删除'></i>"+
	"</a>"
}




function deleteRole(id){
	if(id=="1"){
		layer.msg('不能删除超级管理员角色');
		return ;
	}
	layer.confirm("确认删除该角色信息？", {
		icon: 0
		, title:'' 
		, shade: 0.4
		, offset: "139px"
	}, function(index) { 
		$.ajax({
			url:"#(ctx)/admin/role/delete",
			data:{"id":id},
			dataType:"json",
			success:function(ret){
				$('#role').bootstrapTable("refresh",{silent: true});
			    layer.msg(ret.msg);
			    layer.close(index);   
			},
			error:function(){
				layer.close(index);   
			}
		});                           
		                       
	});
}
</script>
#end
